// 导入jwt
const jwt = require('jsonwebtoken');

// 创建（生成token）
// let token = jwt.sign(用户数据,加密字符串,配置对象);
let token = jwt.sign(
  { username: '张黑娃' },
  'zhangheiwa',
  {
    expiresIn: 1 //单位是秒
  }
)
console.log(token)
// let t = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IuW8oOm7keWogyIsImlhdCI6MTcwOTAyMDUzMCwiZXhwIjoxNzA5MDIwNTkwfQ.Lpu6hTgmij6AjuIafSkdoNcXPwGeBsy5uQjd9Qe0rps';
// 验证token
setTimeout(() => {
  jwt.verify(token, 'zhangheiwa', (err, data) => {
    console.log(err, data)
    if (err) return console.log('验证失败~');
    console.log('验证成功');
  })
}, 2000)